function validate_login_form(thisform)
{
   var username = $("#beanForm input[name='username']").val();
   if(username==""){
   alert("用户名不能为空！");
   	return false;
   }
   var password = $("#beanForm input[name='password']").val();
   if(password==""){
   alert("密码不能为空！");
   	return false;
   }
  var captcha = $("#beanForm input[name='captcha']").val();
  if(captcha==""){
   alert("验证码不能为空！");
   	return false;
   }
    var message = password;
    var ciphertext = encryptByAes(message, aesKey);
    // ciphertext: 8dKft9vkZ4I=
    console.log('ciphertext:', ciphertext);
    $("#beanForm input[name='password']").val(ciphertext)
  return true;
}
$script(window.global.plugin+'/jsrsasign/jsrsasign-all-min.js', 'keyutil',function(){

	var rsa=new RSAKey();
	var keyStr = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCpgdhUVnYUIaP1nigFVSAHPWGQZh1DNg0AX3Wy3xvcQ/+GumIAH5jKd+jo/8/+Ez4DSozETw1PhcBC42wezdCMggRxjBdPbqx2hwl5w79kuGKjxlV2ncaXXzn8gQwli+5a4oZvSx1n9Xq679CRrcSVk+MKvd2pqU6tChQ9FENIFQIDAQAB";
	keyStr = "30819f300d06092a864886f70d010101050003818d0030818902818100a981d85456761421a3f59e28055520073d6190661d43360d005f75b2df1bdc43ff86ba62001f98ca77e8e8ffcffe133e034a8cc44f0d4f85c042e36c1ecdd08c8204718c174f6eac76870979c3bf64b862a3c655769dc6975f39fc810c258bee5ae2866f4b1d67f57abaefd091adc49593e30abddda9a94ead0a143d144348150203010001";
	key = KEYUTIL.getKeyFromPublicPKCS8Hex(keyStr);
	console.log(key)
	var key = new RSAKey();
	  key.readPKCS8PubKeyHex(keyStr);
	console.log(key.encrypt("123456"))
});

$(function() {
	$(".inputElem").mailAutoComplete();
	var val = $("#showErrMsg").attr("val");
	if(val==""){
		$("#showErrMsg").addClass("hide");
	}
    $(".jcaptcha-btn").click(function() {
        $("#randCodeImage").attr("src", '${ctx }/auth/jcaptcha.jpg?'+new Date().getTime()+"&"+_para);
    });
    $("form").validationEngine('attach', {promptPosition : "topRight", autoPositionUpdate : true});
    $(document).on('click', '.toolbar a[data-target]', function(e) {
		e.preventDefault();
		var target = $(this).data('target');
		
		$('.widget-box.visible').removeClass('visible').addClass("hide");//hide others
		$(target).addClass('visible').removeClass("hide");//show target
	 });
    $("form .password").on("keyup change",function(e){
 	   var value = $(this).val();
 	   var form = $(this).closest("form")
 	   var targetname = $(this).attr("targetname");
 	   var val = "";
 	   val = encryptByAes(value,aesKey);
 	   $(form.find("input[name='"+targetname+"']").get(0)).val(val);
     }); 
});
/**
 * 加密数据
 * @param {type} message 待加密的字符串
 * @param {type} key 秘钥
 * @returns {unresolved} 加密后的数据
 */
function encryptByAes(message, key) {
	var sendData = CryptoJS.enc.Utf8.parse(message);
    var key = CryptoJS.MD5(key);
    var encrypted = CryptoJS.AES.encrypt(sendData, key,{iv:key,mode:CryptoJS.mode.CBC,padding:CryptoJS.pad.Iso10126});
    return encrypted.toString();
} 